﻿Public Class FrmPlanning

    'Vastleggen algemene variabelen
    Dim con As SqlConnection
    Dim da As SqlDataAdapter
    Dim ds As New DataSet

    Private Sub BtnHoofdmenu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnHoofdmenu.Click

        Me.Visible = False
        My.Forms.FrmHoofdmenu.Visible = True

    End Sub

    Public Sub Inladen_Tekeningen_retourgevraagd()

        'Creeren connectie
        con = New SqlConnection(My.Settings.Docregdata2ConnectionString)

        Dim standdatum As Date = Me.DateTimePicker1.Value
        Dim werknummer As String = My.Forms.FrmInlogscherm.CmbWerknummer.SelectedValue.ToString

        'sql-command instellen
        Dim selectcmd As SqlCommand
        selectcmd = New SqlCommand("SelectieTekeningRetourgevraagd3", con)
        selectcmd.CommandType = CommandType.StoredProcedure
        selectcmd.Parameters.AddWithValue("@Standdatum", standdatum)
        selectcmd.Parameters.AddWithValue("@Werknummer", werknummer)

        da = New SqlDataAdapter()
        da.SelectCommand = selectcmd

        ds.Clear()
        da.Fill(ds, "TekeningenRetourVraag")

        Me.DataGridView1.AutoGenerateColumns = True
        Me.DataGridView1.DataSource = ds.Tables("TekeningenRetourvraag")
        Me.DataGridView1.Columns("BedrijvenID").Visible = False
        Me.DataGridView1.Columns("TekeningID").Visible = False
        Me.DataGridView1.Columns("DatumID").Visible = False
        Me.DataGridView1.Columns("StatusID").Visible = False

    End Sub

    Private Sub FrmPlanning2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Inladen_Tekeningen_retourgevraagd()

    End Sub

    Private Sub DateTimePicker1_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged

        Inladen_Tekeningen_retourgevraagd()

    End Sub

    Private Sub BtnInvoerbinnen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnInvoerbinnen.Click

        Dim arl_VerzondenNaar As New ArrayList
        Dim arl_Bladnr As New ArrayList
        Dim arl_Naam As New ArrayList
        Dim arl_Datum As New ArrayList
        Dim arl_Status As New ArrayList
        Dim arl_Verzenddatum As New ArrayList
        Dim arl_TekeningID As New ArrayList
        Dim arl_DatumID As New ArrayList
        Dim arl_StatusID As New ArrayList
        'Dim arl_Retourdatum As New ArrayList

        Dim i As Integer = 0, TekeningID As String = "", DatumID As String = "", StatusID As String = "", Verzenddatum As String = "", Verzonden_naar As String = "", Bladnr_Tekening As String = "", Naam_Tekening As String = "", Datum_Tekening As String = "", Status_Tekening As String = ""
        For i = 0 To DataGridView1.RowCount - 1
            If DataGridView1.Rows(i).Cells(0).Value = True Then

                'Verzonden_naar = DataGridView1.Rows(i).Cells(1).Value.ToString
                'Bladnr_Tekening = DataGridView1.Rows(i).Cells(2).Value.ToString
                'Naam_Tekening = DataGridView1.Rows(i).Cells(3).Value.ToString
                'Datum_Tekening = DataGridView1.Rows(i).Cells(4).Value.ToString
                'Status_Tekening = DataGridView1.Rows(i).Cells(5).Value.ToString
                'Verzenddatum = DataGridView1.Rows(i).Cells(6).Value

                Verzonden_naar = DataGridView1.Rows(i).Cells(1).Value.ToString
                TekeningID = DataGridView1.Rows(i).Cells(3).Value.ToString
                DatumID = DataGridView1.Rows(i).Cells(7).Value.ToString
                StatusID = DataGridView1.Rows(i).Cells(9).Value.ToString
                Verzenddatum = DataGridView1.Rows(i).Cells(12).Value

                'Tekeningen opslaan tbv tabel "Verzonden_Tekeningen"
                arl_VerzondenNaar.Add(Verzonden_naar)
                arl_TekeningID.Add(TekeningID)
                arl_DatumID.Add(DatumID)
                arl_StatusID.Add(StatusID)
                arl_Verzenddatum.Add(CDate(Verzenddatum))
                'arl_Bladnr.Add(Bladnr_Tekening)
                'arl_Naam.Add(Naam_Tekening)
                'arl_Datum.Add(Datum_Tekening)
                'arl_Status.Add(Status_Tekening)
                'arl_Retourdatum.Add(CDate(Retourdatum_Tekening))

            End If
        Next

        If con.State = ConnectionState.Closed Then con.Open()

        Dim intRijenArl As Integer
        intRijenArl = arl_TekeningID.Count

        Dim updatecmd As SqlCommand
        updatecmd = New SqlCommand("UpdateVerzonden2", con)
        updatecmd.CommandType = CommandType.StoredProcedure

        da.UpdateCommand = updatecmd

        For n As Integer = 0 To intRijenArl - 1

            updatecmd.Parameters.AddWithValue("@Verzonden_naar", arl_VerzondenNaar.Item(n))
            updatecmd.Parameters.AddWithValue("@Retourdatum", Me.DateTimePicker2.Value.Date)
            updatecmd.Parameters.AddWithValue("@TekeningID", arl_TekeningID.Item(n))
            updatecmd.Parameters.AddWithValue("@DatumID", arl_DatumID.Item(n))
            updatecmd.Parameters.AddWithValue("@StatusID", arl_StatusID.Item(n))
            updatecmd.Parameters.AddWithValue("@Verzenddatum", arl_Verzenddatum.Item(n))
            'updatecmd.Parameters.AddWithValue("@StatusID", CDate(arl_Datum.Item(n)))

            updatecmd.ExecuteNonQuery()
            updatecmd.Parameters.Clear()

        Next

        da.Update(ds, "TekeningenRetourVraag")
        Inladen_Tekeningen_retourgevraagd()

        If con.State = ConnectionState.Open Then con.Close()

    End Sub



End Class